package com.example.demo1.filter;


import org.springframework.core.annotation.Order;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author sunjk
 * @since 2020/9/7
 */
@Order(1)
@WebFilter(filterName = "demo", urlPatterns = "/*")
public class FirstFilter implements Filter {
    @Override
    public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
        // filter 前 应该做的
        System.out.println("filter 前 应该做的");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        // filter 中 应该做的
        HttpServletRequest req = (HttpServletRequest) request;
        System.out.println("filter 中 应该做的");

        filterChain.doFilter(request, response);
        System.out.println("filter 中 应该做的-------------");
    }

    @Override
    public void destroy() {
        // filter 前 应该做的
        System.out.println("filter 销毁 应该做的");
    }
}
